/*
 * CustLogin.java
 * Created on 26-Apr-2011, 1:03:39 AM
 */
package pos.desktop;

import java.math.BigInteger;
import javax.swing.JButton;
import javax.swing.JLabel;
import pos.desktop.controller.CustomerLoginControl;
import pos.entity.Customer;

/**
 *@since 30 MARCH 2011, 5:00 PM
 *@author Anup Mathew
 *<b>Description:<b> <br>This class is used to display
 *the frame for collecting the login information of 
 *the customer.
 */
public class CustLogin extends javax.swing.JFrame {
    
    //Class variables for one to one mapping
    private Customer customer;
    private JLabel jLabelParent;
    private JButton buttonParent;

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @return JButton
     */
    public JButton getButtonParent() {
        return buttonParent;
    }

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @param buttonParent 
     */
    public void setButtonParent(JButton buttonParent) {
        this.buttonParent = buttonParent;
    }

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @return JLabel
     */
    public JLabel getjLabelParent() {
        return jLabelParent;
    }

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @param jLabelParent 
     */
    public void setjLabelParent(JLabel jLabelParent) {
        this.jLabelParent = jLabelParent;
    }
    

    public Customer getCustomer() {
        return customer;
    }

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @param customer 
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /** Creates new form CustLogin */
    public CustLogin(Customer customer) {
        this.customer = customer;
        initComponents();
        setLocation(500, 250);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Login Form");
        setName("LoginFrame"); // NOI18N
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
        jLabel1.setText("Login Form");

        jLabel2.setText("CustomerId:");

        jLabel3.setText("Password:");

        jButton1.setText("Login");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(204, 0, 0));
        jLabel4.setText(" ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(150, 150, 150)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPasswordField1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(167, 167, 167)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(87, 87, 87)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(7, 7, 7)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @since 30 MARCH 2011, 5:00 PM
     * @param evt 
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Customer customer = getCustomer();
        customer.setID(new BigInteger(jTextField1.getText().trim()));
        customer.setPassword(new String(jPasswordField1.getPassword()));
        CustomerLoginControl.validateCustomer(customer);
        if (getCustomer().isAuthenticated()) {
            jLabelParent.setText("Glad to see you " + getCustomer().getName() + ".");
            buttonParent.setText("Logout");
            this.dispose();
        } else {
            jLabel4.setText("Wrong ID & Password Combination, try again.");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
